#ifndef _XGBA_VRAM_H_
#define _XGBA_VRAM_H_
#include "xgba_p.h"

typedef struct xgba_bgcnt_t{
    uint16_t bg_prio:2;
    uint16_t char_base:2;
    uint16_t not_used:2;
    uint16_t mosaic:1;
    uint16_t color256:1;
    uint16_t screen_base:5;
    uint16_t display_area:1;
    uint16_t screen_size:2;
}PACKED xgba_bgcnt_t;

typedef struct xgba_obj_att0_t{
    uint16_t y:8;
    uint16_t r_s_flg:1; //选择,缩放
    uint16_t dsize:1;   //双倍大小
    //uint16_t disable:1; //1:禁止显示
    uint16_t mode:2;    //0默认,1半透明,2obj窗口,3禁止
    uint16_t mosaic:1;  //马赛克
    uint16_t color256:1;    //16色,256色
    uint16_t shape:2;   //0,矩形,1水平,2垂直,3禁止
}PACKED xgba_obj_att0_t;

typedef struct xgba_obj_att1_t{
    uint16_t x:9;
    /*
    9-13 在缩放标志下
    */
    uint16_t not_use:3;
    uint16_t hflip:1;   //水平翻转
    uint16_t vflip:1;   //垂直翻转
    uint16_t size:2;    //大小
    /*
    Size  Square   Horizontal  Vertical
    0     8x8      16x8        8x16
    1     16x16    32x8        8x32
    2     32x32    32x16       16x32
    3     64x64    64x32       32x64
    */
}PACKED xgba_obj_att1_t;

typedef struct xgba_obj_att2_t{
    uint16_t char_num:10;
    uint16_t prio:2;
    uint16_t pal:4;
}PACKED xgba_obj_att2_t;

typedef struct{
    uint16_t offset:9;
    uint16_t nused:7;
}PACKED xgba_bgofs_t;

typedef struct{
    uint32_t frac_p:8;
    uint32_t i_portion:19;
    uint32_t sig:1;
    uint32_t nused:4;
}PACKED xgba_bgx_t;

typedef struct{
    uint16_t x2:8;
    uint16_t x1:8;
}PACKED xgba_winh_t;

typedef struct{
    uint16_t y2:8;
    uint16_t y1:8;
}PACKED xgba_winv_t;

typedef struct{
    uint16_t window0_bg_display:4;
    uint16_t window0_obj_display:1;
    uint16_t window0_color_special:1;
    uint16_t not_used:2;
    uint16_t window1_bg_display:4;
    uint16_t window1_obj_display:1;
    uint16_t window1_color_special:1;
    uint16_t not_used2:2;
}PACKED xgba_winin_t;

typedef struct{
    uint16_t outside_bg_display:4;
    uint16_t outside_obj_display:1;
    uint16_t outside_color_special:1;
    uint16_t not_used:2;
    uint16_t obj_win_bg_display:4;
    uint16_t obj_win_obj_display:1;
    uint16_t obj_win_color_special:1;
    uint16_t not_used2:2;
}PACKED xgba_winout_t;

typedef struct{
    uint16_t bg_mosaic_h:4;
    uint16_t bg_mosaic_v:4;
    uint16_t obj_mosaic_h:4;
    uint16_t obj_mosaic_v:4;
}PACKED xgba_mosic_t;

typedef struct{
    uint16_t    bg_mode:3;
    uint16_t    cgb_mode:1;
    uint16_t    disp_frame:1;
    uint16_t    hblank_interval:1;
    uint16_t    obj_char_vram_map:1;    //obj vram排序,0:2维,1:1维
    uint16_t    forced_blank:1;         //强制空白
    uint16_t    screen_display_bg0:1;
    uint16_t    screen_display_bg1:1;
    uint16_t    screen_display_bg2:1;
    uint16_t    screen_display_bg3:1;
    uint16_t    screen_display_obj:1;
    uint16_t    window0_display_flg:1;
    uint16_t    window1_display_flg:1;
    uint16_t    obj_win_display_flg:1;
}PACKED xgba_dispcnt_t;

typedef struct{
    uint16_t vblank_flg:1;
    uint16_t hblank_flg:1;
    uint16_t vcounter_flg:1;
    uint16_t vblank_irq_enable:1;
    uint16_t hblank_irq_enable:1;
    uint16_t vcounter_irq_enable:1;
    uint16_t nused:2;
    uint16_t vcount_setting:8;
}PACKED xgba_dispstat_t;

typedef struct{
    uint16_t current_scanline:8;
    uint16_t nused:8;
}PACKED xgba_vcount_t;

#define DISPCNT ((xgba_dispcnt_t*)&gba->io[0])
#define DISPSTAT ((xgba_dispstat_t*)&gba->io[4])
#define VCOUNT ((xgba_vcount_t*)&gba->io[6])->current_scanline
#define BG0CNT ((xgba_bgcnt_t*)&gba-io[0x8+0])
#define BG1CNT ((xgba_bgcnt_t*)&gba-io[0x8+2])
#define BG2CNT ((xgba_bgcnt_t*)&gba-io[0x8+4])
#define BG3CNT ((xgba_bgcnt_t*)&gba-io[0x8+8])
#define BG0HOFS ((xgba_bgofs_t*)&gba->io[0x10+0x00])->offset
#define BG0VOFS ((xgba_bgofs_t*)&gba->io[0x12+0x00])->offset
#define BG1HOFS ((xgba_bgofs_t*)&gba->io[0x10+0x04])->offset
#define BG1VOFS ((xgba_bgofs_t*)&gba->io[0x12+0x04])->offset
#define BG2HOFS ((xgba_bgofs_t*)&gba->io[0x10+0x08])->offset
#define BG2VOFS ((xgba_bgofs_t*)&gba->io[0x12+0x08])->offset
#define BG3HOFS ((xgba_bgofs_t*)&gba->io[0x10+0x0C])->offset
#define BG3VOFS ((xgba_bgofs_t*)&gba->io[0x12+0x0C])->offset

#define WIN0H ((xgba_winh_t*)&gba->io[0x40])
#define WIN1H ((xgba_winh_t*)&gba->io[0x42])
#define WIN0V ((xgba_winh_t*)&gba->io[0x44])
#define WIN1V ((xgba_winh_t*)&gba->io[0x46])
#define WININ ((xgba_winin_t*)&gba->io[0x48])
#define WINOUT ((xgba_winout_t*)&gba->io[0x4A])
#define MOSAIC ((xgba_mosic_t*)&gba->io[0x4C])



#endif
